import { WinsleiLogManager } from '@winslei/winsleilog'
import deviceInfo from '@ohos.deviceInfo'
import systemParameterEnhance from '@ohos.systemParameterEnhance'

const TAG = 'DeviceUtil'

export class DeviceUtil {
  constructor() {
    WinsleiLogManager.hilogIWithTag(TAG, `constructor`)
  }

  // 设备类型
  deviceType(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.deviceType)}`)
    return deviceInfo.deviceType
  }

  // 设备厂家名称
  manufacture(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.manufacture)}`)
    return deviceInfo.manufacture
  }

  // 设备品牌名称
  brand(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.brand)}`)
    return deviceInfo.brand
  }

  // 外部产品系列
  marketName(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.marketName)}`)
    return deviceInfo.marketName
  }

  // 产品系列
  productSeries	(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.productSeries)}`)
    return deviceInfo.productSeries
  }

  // 认证型号
  productModel(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.productModel)}`)
    return deviceInfo.productModel
  }

  // 内部软件子型号
  softwareModel(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.softwareModel)}`)
    return deviceInfo.softwareModel
  }

  // 硬件版本号
  hardwareModel	(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.hardwareModel)}`)
    return deviceInfo.hardwareModel
  }

  // Bootloader版本号
  bootloaderVersion(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.bootloaderVersion)}`)
    return deviceInfo.bootloaderVersion
  }

  // 应用二进制接口（Abi）列表
  abiList(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.abiList)}`)
    return deviceInfo.abiList
  }

  // 设备Udid
  // 需要权限：ohos.permission.sec.ACCESS_UDID
  udid(): string {
    WinsleiLogManager.hilogIWithTag(TAG, `udid: ${JSON.stringify(deviceInfo.udid)}`)
    return deviceInfo.udid
  }

  public getBootHardware(): string {
    let bootHardware = systemParameterEnhance.getSync('ohos.boot.hardware', 'default')
    WinsleiLogManager.hilogIWithTag(TAG, `bootHardware: ${JSON.stringify(bootHardware)}`)
    return bootHardware ? bootHardware : ''
  }
}